package com.xhwl.logistics.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum VehicleDeviceHandlerEnum {
        VEHICLE_DEVICE_NOTHING(-1,"vehicleParkingLotNothingDeviceHandlerImpl"),
        VEHICLE_DEVICE_COSON(52, "vehicleParkingLotCoSonDeviceHandlerImpl");

        private final Integer productId;

        private final String deviceHandlerName;

        private static final Map<Integer, VehicleDeviceHandlerEnum> map;
        static {
            map = new HashMap<>();
            for (VehicleDeviceHandlerEnum vehicleDeviceHandlerEnum : VehicleDeviceHandlerEnum.values()) {
                map.put(vehicleDeviceHandlerEnum.getProductId(), vehicleDeviceHandlerEnum);
            }
        }

//        public static VehicleDeviceHandlerEnum toVehicleDeviceHandlerEnum(Integer productId) {
//            return Optional.ofNullable(map.get(productId)).orElse(VEHICLE_DEVICE_NOTHING);
//        }

    public static VehicleDeviceHandlerEnum toVehicleDeviceHandlerEnum(Integer productId) {
        for (VehicleDeviceHandlerEnum vehicleDeviceHandlerEnum : VehicleDeviceHandlerEnum.values()) {
            if (vehicleDeviceHandlerEnum.productId.equals(productId)) {
                return vehicleDeviceHandlerEnum;
            }
        }
//        throw new IllegalArgumentException("非法的VehicleParkingLotHandlerEnum的productId，无法映射到对应的厂商");
        return VEHICLE_DEVICE_NOTHING;
    }
}

